<template>
  <!--  头部-->
  <div>
    <div style="display: flex; height: 60px; line-height: 60px; border-bottom: 1px solid #ccc">
      <div style="width: 350px; text-align: center; display: flex; padding-left: 30px" >
        <div style="width: 60px;">
          <img src="../../assets/OIP-C.jpg" alt="" style="width: 40px; position: relative; top: 5px">
        </div>

        <h3 style="flex: 1; color: #3a8ee6">综合服务系统前台</h3>
        </div>
      <div style="flex: 1">
        <el-menu :default-active="num.toString()" class="el-menu-demo" mode="horizontal" router>
          <el-menu-item index="/front/home">首页</el-menu-item>
          <el-menu-item index="/front/video">视频播放</el-menu-item>
          <el-menu-item index="/front/article">文章列表</el-menu-item>
          <!--          <el-menu-item index="3" disabled>消息中心</el-menu-item>-->
          <el-menu-item index="/front/cart">我的购物车</el-menu-item>
          <el-menu-item index="/front/ordersPlus">我的订单</el-menu-item>
          <el-submenu index="2">
            <template slot="title">更多</template>
            <el-menu-item index="/front/im">聊天室</el-menu-item>
            <el-menu-item index="/front/exam">考试</el-menu-item>
            <el-menu-item index="2-3">报修</el-menu-item>
          </el-submenu>

        </el-menu>
        <!--        导航菜单-->
<!--        <ul style="list-style: none; background-color: #98f898;">-->
<!--          <li class="item">-->
<!--            <router-link to="/home">菜单1</router-link>-->
<!--          </li>-->
<!--          <li class="item">-->
<!--            <el-dropdown size="medium">-->
<!--              <span>更多菜单<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i></span>-->
<!--              <el-dropdown-menu slot="dropdown">-->
<!--                <el-dropdown-item>黄金糕</el-dropdown-item>-->
<!--                <el-dropdown-item>狮子头</el-dropdown-item>-->
<!--                <el-dropdown-item>螺蛳粉</el-dropdown-item>-->
<!--                <el-dropdown-item>双皮奶</el-dropdown-item>-->
<!--                <el-dropdown-item>蚵仔煎</el-dropdown-item>-->
<!--              </el-dropdown-menu>-->
<!--            </el-dropdown>-->
<!--          </li>-->
<!--          <li class="item">菜单3</li>-->
<!--          <li class="item">菜单4</li>-->
<!--          <li class="item">菜单5</li>-->
<!--        </ul>-->
      </div>
      <div style="width: 200px;">
        <div v-if="!user.username" style="text-align: right; padding-right: 30px">
          <el-button @click="$router.push('/frontLogin')">登录</el-button>
          <el-button @click="$router.push('/frontRegister')">注册</el-button>
        </div>

        <div v-else>
          <el-dropdown style="width: 150px; cursor: pointer; text-align: right;">
            <div style="display: inline-block">
              <img :src="user.avatarUrl" alt="" style="width: 30px; border-radius: 50%; position: relative; top: 10px; right: 5px;">
              <span>{{user.nickname}}</span><i class="el-icon-arrow-down" style="margin-left: 5px"></i>
            </div>
            <el-dropdown-menu slot="dropdown" style="width:100px; text-align: center">
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <router-link to="/front/password" style="text-decoration: none; color: #606266">修改密码</router-link>
              </el-dropdown-item>
              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <router-link to="/front/FrontPerson" style="text-decoration: none; color: #606266">个人信息</router-link>
              </el-dropdown-item>

              <el-dropdown-item style="font-size: 14px; padding: 5px 0">
                <span style="text-decoration: none; color: #606266" @click="logout">退出</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
export default {
  name: "Front",
  props:["user"],
  data() {
    return{
      num:1
    }
  },
  methods: {
    logout(){
      this.$router.push("/frontLogin")
      localStorage.removeItem("user")
      localStorage.removeItem("menus")
      setTimeout(() => {
        location.reload();
      }, 500);
      this.$message.success("退出成功")
    },

    //刷新一次数据让头像实时更新，让头像实时更新
    getUser(){
      let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
      this.request.get("/user/username/" + username).then(res=>{
        //重新赋值最小user数据
        this.user = res.data
      })

    }

  }
}
</script>

<style scoped>
.item {
  display: inline-block;
  width: 100px;
  color: #46c2fc;
  text-align: center;
  cursor: pointer;
}

.item:hover {
  background-color: pink;
}
</style>